<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ page import="com.google.appengine.api.users.User"%>
<%@ page import="com.google.appengine.api.users.UserService"%>
<%@ page import="com.google.appengine.api.users.UserServiceFactory"%>
<%@ page import="studystat.*"%>
<%@ page import="java.util.List"%>

<html>

<head>
<Title>Home</Title>
<%
	UserService userService = UserServiceFactory.getUserService();
	User user = userService.getCurrentUser();
%>
<link rel="stylesheet" href="customThemeJ/themes/StudyStatTheme1.min.css" />
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0rc2/jquery.mobile.structure-1.0rc2.min.css" />	
<script src="http://code.jquery.com/jquery-1.7.1.js"></script> 
<script src="http://code.jquery.com/mobile/1.0rc2/jquery.mobile-1.0rc2.min.js"></script>
<script type="text/javascript" src="timer.js"></script>
<script type="text/javascript">
    $(document).ready(function () {
		  showOnlyEl("studeren");
		});
    
    function getStartTijd() {
        var duurString = "";
        	<%Student student = StudentManager.getInstance().getStudent(user.getUserId());
    				// Als er nog een activiteit bezig is
    				Activiteit acti = student.getNietGestopteActiviteit();
    				if (acti !=null) { 
    					if(acti.getStopTijd() != null) {%>
    					ret = false;
    					alert("U moet uw form nog invullen");
    					$(window.location).attr('href', '/login');
    					<%}
    					else if(acti instanceof studystat.Sport){ %>
    					alert("U bent reeds met een andere <%= acti.getClass().getSimpleName().toLowerCase() %>-activiteit bezig");
    					$(window.location).attr('href', 'main.jsp');
    					<%}
    					else if(acti instanceof studystat.Studie) {%>
    						duurString = <%=Long.toString(student.getNietGestopteActiviteit().getDuurActiNogBezig())%>;
    					<%}
    				}
    				%>
    	return duurString;
    	}
</script>

</head>

<body onload="startTimer(getStartTijd())">
	<div data-role="page" data-theme="b">

		<!-- Titelbalk -->
		<div data-role="header" data-position="inline" data-theme="b">
		<a href="achievement.jsp" data-icon="star" class="ui-btn-left" rel="external">Achievements</a>
			<h1>The Real Study Stat</h1>
			<a href="option.jsp" data-icon="gear" class="ui-btn-right">Options</a>
			<div data-role="navbar">
				<ul>
					<li><a href="main.jsp" rel="external">Home</a></li>
					<li><a href="statistieken.jsp" rel="external">Statistieken</a></li>
					<li><a href="contact.html" rel="external">Contact</a></li>
					<li><a href="about.html" rel="external">Over Ons</a></li>
					<li><a href="<%= userService.createLogoutURL("/login") %>" rel="external">Uitloggen</a></li>
				</ul>
			</div>
		</div>


		<div data-role="content">
			<%
				if (user != null) {
			%>
			<div class="ui-grid-a">
				<div class="ui-block-a" id="keuzemenu" style="width: 20%">
				</div>

				<!-- Paginainhoud -->
				<div id="content" class="ui-block-b" style="width: 60%">
					<div id="studeren">
						<p>U bent al</p>
						<div id="timer"></div>
						<p>aan het studeren.</p>
						<form action="/opmeten" name="stoppauze" id="stoppauze"
							method="post" data-ajax="false">
							<input type="hidden" name="type" value="studie" /> <input
								type="hidden" name="userID" value="<%=user.getUserId()%>" /> <input
								type="submit" name="stop" value="stop" />
						</form>
						<form action="" name="pauze" id="pauze" method="get">
							<input type="button" name="pauzeknop" value="pauze"
								id="pauzeknop" onclick="pauzeStart('<%=user.getUserId()%>')" />
						</form>
					</div>

					<div id="pauzetekst">
						<p>U bent aan het pauzeren.</p>
						<form action="" name="hervatten" id="hervatten" method="get">
							<input type="button" name="hervatten" value="hervatten"
								id="hervatknop" onclick="pauzeStop('<%=user.getUserId()%>')" />
						</form>
					</div>
					<%
						} else {
					%>
					<div id="content">
						<p>
							<a href="<%=userService.createLoginURL("/login")%>">Log in
								om verder te gaan</a>
						</p>
					</div>
					<%
						}
					%>


				</div>
			</div>
</body>
</html>
